package com.woniuxy.cloud.carl.marketing.app.apiImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.cloud.carl.marketing.client.FullDiscountCouponClient;
import com.woniuxy.cloud.carl.marketing.client.param.AddFullDiscount;
import com.woniuxy.cloud.carl.marketing.client.param.GetCouponParam;
import com.woniuxy.cloud.carl.marketing.infra.model.Coupon;
import com.woniuxy.cloud.carl.marketing.infra.model.Deduction;
import com.woniuxy.cloud.carl.marketing.infra.model.FullDiscountCoupon;
import com.woniuxy.cloud.carl.marketing.service.CouponService;
import com.woniuxy.cloud.carl.marketing.service.FullDiscountCouponService;
import com.woniuxy.exceptions.MallException;
import com.woniuxy.result.CommonResultCodeEnum;
import com.woniuxy.result.Result;
import com.woniuxy.utils.Assert;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
@RestController
public class FullDiscountCouponAPIImpl implements FullDiscountCouponClient {
    @Autowired
    private FullDiscountCouponService fullDiscountCouponService;
    @Autowired
    private CouponService couponService;
    @Override
    public Result addFullDiscountCoupon(AddFullDiscount param) {
        Result result = fullDiscountCouponService.addFullDiscountCoupon(param);
        return result;
    }

    @Override
    public Result<Page<FullDiscountCoupon>> getFullDiscountCoupon(GetCouponParam param) {
        if (param.getPageNum()==null||param.getPageNum()<1)
            param.setPageNum(1);
        if (param.getPageSize()==null||param.getPageSize()<1)
            param.setPageSize(8);
        Result<Page<FullDiscountCoupon>> coupon = fullDiscountCouponService.getCoupon(param);
        return coupon;
    }

    @Override
    public Result<FullDiscountCoupon> useFullDiscount(BigDecimal price, Long userId, Long couponId) {

        return fullDiscountCouponService.useFullDiscount(price, couponId.toString());
    }


}
